package com.kaishengit.dao;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.kaishengit.pojo.Message;
import com.kaishengit.pojo.Project;

@Repository
public class MessageDao extends BaseDao<Message,Integer>{
	private int count=10;
	@SuppressWarnings("unchecked")
	public List<Message> findByProject(Project project, int p) {
		Query query = getSession().createQuery("from Message where project=:project order by createtime desc");
		query.setParameter("project", project);
		query.setFirstResult((p-1)*count);
		query.setMaxResults(count);
		return query.list();
	}
	public long count(Project project){
		Query query = getSession().createQuery("select count(*) from Message where project=:project ");
		query.setParameter("project", project);
		return (Long) query.uniqueResult();
	}
	
}
